package com.blockmeta.bbs.immodule.widget;

import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import com.blockmeta.bbs.baselibrary.utils.ToastUtil;
import com.blockmeta.bbs.baselibrary.utils.loading.ProgressBarUtil;
import com.blockmeta.bbs.businesslibrary.net.pojo.BaseImResponse;
import com.blockmeta.bbs.businesslibrary.net.retrofit.RetrofitFactory;
import com.blockmeta.bbs.businesslibrary.net.rxjava.CommonSubscriber;
import com.blockmeta.bbs.businesslibrary.net.rxjava.RxUtil;
import com.blockmeta.bbs.businesslibrary.util.AccountHelper;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.net.api.AddFriendApi;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;


public class IMConfirmPop extends IMSysPopup {


    OnRequestSuccessListiener mOnRequestSuccessListiener;
    private InputMethodManager mInputMethodManager;

    public interface OnRequestSuccessListiener {
        void requestSuccess();
    }

    public IMConfirmPop(Context pContext) {
        super(pContext);
    }

    public IMConfirmPop(Context pContext, OnRequestSuccessListiener requestSuccessListiener) {
        super(pContext);
        mOnRequestSuccessListiener = requestSuccessListiener;
    }

    @Override
    protected void onDismiss(DialogInterface dialog) {

    }

    @Override
    protected void initializeView(View pView) {
        try {
            m_dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mInputMethodManager = (InputMethodManager) m_editMsg.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        m_tvTitle.setText("确定发布该公告信息");
        m_editMsg.setVisibility(View.GONE);
        m_btnCancel.setText(R.string.im_popup_resend_cancel);
        m_btnAction.setText(R.string.im_popup_clear_history_confirm);
    }

    @Override
    protected void onActionClick() {
        if (mOnRequestSuccessListiener != null) {
            mOnRequestSuccessListiener.requestSuccess();
        }

        dismissDialog();
    }

    @Override
    protected void onCancelClick() {
        hideSoftInput();
    }

    public void show() {
        showDialog();
    }

    /**
     * 隐藏软件盘
     */
    private void hideSoftInput() {
        mInputMethodManager.hideSoftInputFromWindow(m_editMsg.getWindowToken(), 0);
    }
}
